package cn.zealon.readingcloud.collection.common;

import cn.zealon.readingcloud.collection.service.ESOperateService;
import cn.zealon.readingcloud.common.pojo.book.Book;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SpringRabbitListener {
    @Autowired
    private ESOperateService esOperateService;

    private static Logger log = LoggerFactory.getLogger(SpringRabbitListener.class);

    //注解监听队列后，方法实参就是该队列的消息
    @RabbitListener(queues = "booksqueue")
    public void listenSimpleQueueMessage(Book book) throws InterruptedException {
        log.debug("消费者接收到消息：【" + book.getBookName() + "】");
        Thread.sleep(2000);
        esOperateService.inputBookToES(book);
    }
}